import json

import click
from app.auth.script.auth_click import AuthClick


@click.group()
def auth_cli():
    pass


@auth_cli.command("auth_user_info_sync_from_ldap")
def auth_user_info_sync_from_ldap():
    """
    从ldap数据库同步用户信息
    python manage.py auth_user_info_sync_from_ldap
    """
    auth_click = AuthClick()
    auth_click.user_info_sync_from_ldap()


@auth_cli.command("auth_create_admin")
def auth_create_admin():
    """
    创建超级管理员用户
    python manage.py auth_create_admin
    """
    auth_click = AuthClick()
    res = auth_click.auth_create_role_admin()
    res = auth_click.auth_create_account_admin()
    click.echo(json.dumps(res))


@auth_cli.command("auth_create_account")
@click.option('--name', type=str, help="账号名字")
def auth_create_admin(name):
    """
    创建普通用户
    python manage.py auth_create_account --name 
    """
    auth_click = AuthClick()
    res = auth_click.auth_create_account(name)
    click.echo(json.dumps(res))
    
    
    
@auth_cli.command("auth_update_permissions")
def update_permissions():
    """
    更新权限列表
    python manage.py update_permissions
    """
    auth_click = AuthClick()
    res = auth_click.auth_update_permissions()
    
    
@auth_cli.command("auth_check_permissions")
def update_permissions():
    """
    查看没有配置权限的路由
    python manage.py auth_check_permissions
    """
    auth_click = AuthClick()
    res = auth_click.auth_check_permissions()